package cn.com.majiang.config.result;


import cn.com.majiang.config.enums.ResultCode;

/**
 * Created by jiangyanxin on 16/9/1.
 */
public class BaseResult<T> {
    private String status;
    private String message;
    private T result;

    public static BaseResult build(ResultCode resultCode){
        BaseResult baseResult = new BaseResult();
        baseResult.setStatus(resultCode.getCode());
        baseResult.setMessage(resultCode.getMessage());
        return baseResult;
    }

    public static <T> BaseResult<T> build(ResultCode resultCode, T data){
        BaseResult baseResult = build(resultCode);
        baseResult.setResult(data);
        return baseResult;
    }

    public static <T> BaseResult<T> build(T data){
        BaseResult baseResult = build(ResultCode.REQUEST_SUCCESS);
        baseResult.setResult(data);
        return baseResult;
    }

    public static BaseResult build(String code, String message){
        BaseResult result = new BaseResult();
        result.setStatus(code);
        result.setMessage(message);
        return result;
    }

    public static <T> BaseResult<T> build(String code, String message, T data){
        BaseResult result = new BaseResult();
        result.setStatus(code);
        result.setMessage(message);
        result.setResult(data);
        return result;
    }

    /**
	 * 判断返回是否成功 true成功 false不成功
	 */
	public static boolean isSuccess(BaseResult baseResult){
		String code = baseResult.getStatus();
		if(code!=ResultCode.REQUEST_SUCCESS.getCode()){
			return false;
		}else{
			return true;
		}
	}
   

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    

    public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public T getResult() {
		return result;
	}

	public void setResult(T result) {
		this.result = result;
	}

	public static void main(String[] args) {
        BaseResult baseResult = BaseResult.build(ResultCode.REQUEST_SUCCESS);
    }
}
